from flask import Blueprint, jsonify, request
from app.err_no import errno_no
from loguru import logger
import json
import traceback
from app.db.mongoClient import MongoError
from app.db import dbServerQuery
from app.settings import __version__

blueprint = Blueprint('server_query', __name__, url_prefix='/api/server')


@blueprint.route('/v1/query_schoolNameLogo', methods=['POST'])
def query_schoolNameLogo():
    '''
    查询学校名称及logo
    '''
    try:
        res = dbServerQuery.querySchoolNameLogo()
        if res is None:
            return jsonify(errno_no.ErrServerDocumentNotExist.data(None))
            
        return jsonify(errno_no.OK.data(res))
    except MongoError as e:
        logger.error(f'操作mongo异常:{e.__dict__},traceback={traceback.format_exc()}')
        return jsonify(errno_no.ErrServerRuntime.data(None))
    except Exception as e:
        logger.error(f'业务异常:{e.__dict__},traceback={traceback.format_exc()}')
        return jsonify(errno_no.ErrServerRuntime.data(None))


@blueprint.route('/v1/server_version', methods=['POST'])
def server_version():
    data = { 
        'version': __version__
    }
    return jsonify(errno_no.OK.data(data))